#include <iostream>
#include <vector>
#include <cstring>
#define ll long long

using namespace std;

int f[300000];

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--){
		string sa,sb;
		cin >> sa >> sb;
		int alen = sa.size();
		int blen = sb.size();
		if((alen == 1 && sa[0] == '0') || (blen == 1 && sb[0] == '0')){
			cout << '0';
		}else{
			vector<int> a;
			a.reserve(alen);
			vector<int> b;
			a.reserve(blen);
			for(int i = alen-1; i >= 0; --i){
				if(sa[i] == '1'){
					a.push_back(alen - i - 1);
				}
			}
			for(int i = blen-1; i >= 0; --i){
				if(sb[i] == '1'){
					b.push_back(blen - i - 1);
				}
			}
			
			vector<pair<int,int>> ap;
			vector<pair<int,int>> bp;
			int l = a[0],r = a[0];
			if(a.size() == 1){
				ap.push_back({l,r});
			}else{
				for(int i = 1; i < a.size(); ++i){
					if(a[i] == a[i-1] + 1){
						++r;
						if(i == a.size() - 1) ap.push_back({l,r});
					}else{
						ap.push_back({l,r});
						l = a[i];
						r = l;
						if(i == a.size() - 1) ap.push_back({l,r});
					}
				}
			}
			
			l = b[0],r = b[0];
			if(b.size() == 1){
				bp.push_back({l,r});
			}else{
				for(int i = 1; i < b.size(); ++i){
					if(b[i] == b[i-1] + 1){
						++r;
						if(i == b.size() - 1) bp.push_back({l,r});
					}else{
						bp.push_back({l,r});
						l = b[i];
						r = l;
						if(i == b.size() - 1) bp.push_back({l,r});
					}
				}
			}
			
			memset(f,0,sizeof(f));
			ll num1 = alen * bp.size(),num2 = blen * ap.size();
			if(num1 >= num2){
				for(auto val : a){
					for(auto p : bp){
						++f[val+p.first];
						--f[val+p.second+1];
					}
				}
				for(int i = 1; i < 300000-4; ++i){
					f[i] += f[i-1];
				}
				int g = 0;
				for(int i = 0; i < 300000-4; ++i){
					g = f[i] / 2;
					f[i+2] += g;
					f[i+4] += g;
					f[i] %= 2;
				}
				int cnt = 0;
				for(int i = 300000-4-1; i >= 0; --i){
					if(f[i]){
						cnt = i;
						break;
					}
				}
				while(cnt != -1){
					cout << f[cnt];
					--cnt;
				}
			}else{
				for(auto val : b){
					for(auto p : ap){
						++f[val+p.first];
						--f[val+p.second+1];
					}
				}
				for(int i = 1; i < 300000-4; ++i){
					f[i] += f[i-1];
				}
				int g = 0;
				for(int i = 0; i < 300000-4; ++i){
					g = f[i] / 2;
					f[i+2] += g;
					f[i+4] += g;
					f[i] %= 2;
				}
				int cnt = 0;
				for(int i = 300000-4-1; i >= 0; --i){
					if(f[i]){
						cnt = i;
						break;
					}
				}
				while(cnt != -1){
					cout << f[cnt];
					--cnt;
				}
			}
		}
		if(t) cout << endl;
	}

	return 0;
}

